//
//  CZMainViewController.swift
//  swift微博
//
//  Created by ray on 16/2/29.
//  Copyright © 2016年 ray. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
   
        addChildViewControllers()
    }
    
    
    func addChildViewControllers() {
        //首页
        let homeVC = CZHomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        //消息
        let messageVC = CZMessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //发现
        let discoverVC = CZDiscoverViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        //我
        let profileVC = CZProfileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    
   
    //添加tabBar的子控制器
    func addChildViewController(controller: UIViewController, title: String, imageName: String) {
        //设置title
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        
        //设置选中图片
        controller.tabBarItem.selectedImage = UIImage(named: imageName+"_"))
        
        //设置选中的文字颜色
        //添加到tabBar为子控制器,包装导航控制器
        addChildViewController(UINavigationController(rootViewController: controller))
    }



}
